/*
 * This file is part of the Try! Engine project.
 *
 * Copyright 2010-2011 Emanuele Bertoldi. All rights reserved.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * You should have received a copy of the modified BSD License along with this
 * program. If not, see <http://www.opensource.org/licenses/bsd-license.php>
 */

#ifndef TRY_PROJECT_H
#define TRY_PROJECT_H

#include <behavior.h>
#include <QtCore/QStringList>

namespace Try
{
    class Project : public QObject, public Behavior
    {
        Q_OBJECT

    protected:
        QString m_name;
        QString m_description;
        QString m_author;
        QString m_filename;

        QStringList m_assetLibraries;
        ObjectList m_selectedObjects;

    public:
        Project(
            const QString& name = "New Project",
            const QString& description = "",
            const QString& author = "",
            const QStringList& asset_libs = QStringList(),
            QObject* parent = 0
        );
        virtual ~Project();

        QString name() const;
        QString description() const;
        QString author() const;
        QString filename() const;

        QStringList assetLibraries() const;
        int assetLibraryCount() const;

        QString findAvailableObjectName(const QString& name) const;

        int selectedObjectCount() const;
        ObjectList selectedObjects() const;
        int selectedObjectIdFromName(const String& name) const;

        Object* selectedObject(const String& name) const;
        Object* selectedObject(int id) const;

        bool isObjectSelected(Object* object) const;
        bool isObjectSelected(const String& name) const;
        bool isObjectSelected(int id) const;

        bool load(const QString& filename = "");
        bool save(const QString& filename = "");

        void setName(const QString& name);
        void setDescription(const QString& description);
        void setAuthor(const QString& author);

        void addAssetLibrary(const QString& filename);
        void removeAssetLibrary(const QString& filename);

        Object* createObject();
        Object* copyObject(Object* object);
        Object* copyObject(const String& name);
        Object* copyObject(int id);
        void selectObject(Object* object);
        void selectObject(const String& name);
        void selectObject(int id);
        void selectAllObjects();
        void deselectObject(Object* object);
        void deselectObject(const String& name);
        void deselectObject(int id);
        void deselectAllObjects();

    protected:
        void onMessage(const Message& msg, Object* sender, Property* property);

    signals:
        void loaded();
        void saved();
        void closed();
        void changed();
        void selectionChanged();
    };

    typedef QList<Project*> ProjectList;
}

#endif // TRY_PROJECT_H
